package com.tiantianyuegou.util;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.tiantianyuegou.R;


/**
 * Created by ivany on 2016/1/15.
 */
public class ToastUtilsCenter extends Toast {

	public ToastUtilsCenter(Context context) {
		super(context);
	}

	public static Toast makeText(Context context, CharSequence text,boolean isSuccess) {
		Toast result = new Toast(context);

		// 获取LayoutInflater对象
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		// 由layout文件创建一个View对象
		View layout = inflater.inflate(R.layout.toast_view_center,null);
		// 实例化ImageView和TextView对象
		ImageView imageView= (ImageView) layout.findViewById(R.id.img_success);
		if(isSuccess){
			imageView.setImageResource(R.mipmap.success_icon);
		}else{
			imageView.setImageResource(R.mipmap.shibai);
		}
		TextView textView = (TextView) layout.findViewById(R.id.text_content);
		textView.setText(text);
		result.setView(layout);
		result.setGravity(Gravity.CENTER, 0, 0);
		result.setDuration(Toast.LENGTH_SHORT);
		return result;
	}

}